<?php
declare(strict_types=1);

// 支付方式选项解析函数
// 该函数用于将API返回的数据映射为下拉选项所需的格式
// 输入: res(响应对象), rule(规则对象), api(API对象)
// 输出: 包含value和label的对象数组
$paymentOptionsParser = "[[FORM-CREATE-PREFIX-function (res, rule, api) {
    return res.data.map(item => ({
        value: item.id,
        label: item.name
    }));
}-FORM-CREATE-SUFFIX]]";

// 支付配置项
$paymentConfig = [
    [
        "type" => "checkbox",
        "field" => "pay_type",
        "title" => "支付方式",
        "info" => "这里可以开启关闭支付方式",
        "effect" => [
            "fetch" => [
                "action" => "{{API_BASE_URL}}/admin/payment",
                "method" => "GET",
                "dataType" => "json",
                "headers" => [
                    "Authorization" => "Bearer {{API_TOKEN}}"
                ],
                "query" => [],
                "data" => [],
                "parse" => $paymentOptionsParser,
                "beforeFetch" => "",
                "onError" => "",
                "to" => "options"
            ]
        ],
        "\$required" => false,
        "props" => [
            "_optionType" => 1
        ],
        "_fc_id" => "id_Fpr6mdk6u0kpafc",
        "name" => "ref_Forzmdk6u0kpagc",
        "display" => true,
        "hidden" => false,
        "_fc_drag_tag" => "checkbox"
    ],
];

return $paymentConfig;